package org.v2ray.rocket.proxy.support.utils

import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.core.content.res.ResourcesCompat
import org.v2ray.rocket.proxy.support.base.BaseApplication

object ResourceUtil {

    /**
     * 非activity中调用，例如fragment，解决fragment上下文为null的问题
     *
     * @param resId
     */
    fun resourceString(@StringRes resId: Int): String {
        return BaseApplication.context.getString(resId)
    }

    /**
     * @see resourceString
     * @param resId
     */
    fun resourceColor(@ColorRes resId: Int): Int {
        return ResourcesCompat.getColor(BaseApplication.context.resources, resId, null)
    }

    /**
     * @see resourceString
     * @param resId
     */
    fun resourceDrawable(@DrawableRes resId: Int): Drawable? {
        return ResourcesCompat.getDrawable(BaseApplication.context.resources, resId, null)
    }
}